package com.da.mybatis.util;

import java.util.Date;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.da.mybatis.model.User;

/**
 * @author JokerDa.
 * @date 2021/6/1 10:44
 * Description:
 */
public class TokenUtil {
    public static String getToken(User user) {
        Date start = new Date();
        //5分钟有效时间
        long currentTime = System.currentTimeMillis() + 5 * 60 * 1000;
        Date end = new Date(currentTime);
        String token = "";
        token = JWT.create().withAudience(String.valueOf(user.getId()))
            .withIssuedAt(start).withExpiresAt(end)
            .sign(Algorithm.HMAC256(user.getName()));
        return token;
    }
}
